#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/3/21 17:53
# @Author  : 柳晓飞
# @Site    :
# @File    : test.py
# @Software: PyCharm

def isHu(cardList):
    if cardList == None or type(cardList) != list or len(cardList) < 9:
        print '给定如下的牌不能判断是否胡牌'
        print cardList
        return False
    cardList.sort()
    print cardList
    del3SameCard(cardList)
    print cardList
    del3Shunzi(cardList)
    print cardList
def isPeng(cardList,cardNum):
    if cardList == None or type(cardList) != list or len(cardList) < 8:
        print '给定如下的牌不能判断是否碰牌'
        print cardList
        return False
    if cardNum in cardList:
        if cardList.count(cardNum)==2:
            return True
    return False

def del3SameCard(cardList):  # 去掉三张一样的牌
    for i in cardList:
        if 3 == cardList.count(i):
            for j in range(0, 3):
                cardList.remove(i)
            del3SameCard(cardList)
            break
def del3Shunzi(cardList): #去掉三个顺子
    length = len(cardList)
    if length<3:
        return
    first = cardList[0]
    if ((first+1) in cardList) and ((first+2) in cardList):
        cardList.remove(first)
        cardList.remove(first+1)
        cardList.remove(first+2)
        del3Shunzi(cardList)



if __name__ == "__main__":

    cardList = [1, 3, 8, 7, 4, 1, 1, 2, 2]
    value = isPeng(cardList[:],1)
    print cardList
    print value